package com.yxkj.syh.app.huarong.data_center.model;

import com.syh.app.basic.utils.net.ApiObserver;
import com.yxkj.syh.app.huarong.util.RetrofitHelper;
import com.trello.rxlifecycle2.LifecycleTransformer;
import com.yxkj.syh.app.huarong.api.AuthApi;

import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * 创建者：SYH
 * 时间：2020/5/22 13:57
 * 编辑者：SYH、
 * 标签：
 * 补充说明：
 */
public class AuthModel {
    private static AuthModel authModel;

    private AuthModel() {
    }

    public static AuthModel getAuthModel() {
        if (authModel == null) authModel = new AuthModel();
        return authModel;
    }

    private AuthApi getAuthApi() {
        return RetrofitHelper.createApi(AuthApi.class);
    }

    public void login(Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getAuthApi().login(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void logout(LifecycleTransformer transformer, ApiObserver apiObserver) {
        getAuthApi().logout().compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void verCode(Map<String, Object> pMap, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getAuthApi().verCode(pMap).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void commitAuthData(Map<String, Object>  supplierAuth, LifecycleTransformer transformer, ApiObserver apiObserver) {
        getAuthApi().commitAuthData(supplierAuth).compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

    public void authInfo(LifecycleTransformer transformer, ApiObserver apiObserver) {
        getAuthApi().authInfo().compose(transformer).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(apiObserver);
    }

}
